package org.testcode;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.cglib.beans.BeanMap;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tomtop.core.utils.JSONUtils;

/**
 * Hello world!
 *
 */
public class BeanToMapTest 
{
	private static ObjectMapper objectMapper=new ObjectMapper();
	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws JsonProcessingException {
		Map<String,?> tag=new HashMap<>();
		User su=new User(3,"232");
		User tage=new User();
		//把一个对象的参数拷贝到另一个参数
		BeanUtils.copyProperties(su, tage);
		//把一个对象拷贝为map
		tag.putAll(BeanMap.create(tage));
		//Map转化为对象
		User tage1= JSONUtils.fromObject(tag, User.class);
		System.err.println(objectMapper.writeValueAsString(tage1));
	}
}
